var pageSize = 10;
var pageNum = 1;
var page;
var list;
var layer;
var index;
var flag = 1;

$(function () {
    $("#menuId").val(sessionStorage.menuId);
    layui.use(['laydate', 'element', 'laypage', 'layer'], function () {
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        lement = layui.element();//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
    });
    setTimeout(function () {
        partnerOrder();
    }, 200);

    $("#tui_jian").click(function () {
        if (flag != 1) {
            flag = 1;
            pageSize = 10;
            pageNum = 1;
            partnerOrder();
        }
    });

    $("#liu_shui").click(function () {
        if(flag != 2) {
            flag = 2;
            pageSize = 10;
            pageNum = 1;
            partnerOrder();
        }
    });
});

//代理商排行
function partnerOrder() {
    var menuId = $("#menuId").val();

    var params = {
        "type": "query",
        "menuId": menuId,
        "flag": flag,
        "pageSize": pageSize,
        "pageNum": pageNum
    };
    $.ajax({
        type: "post",
        url: "/partner/order",
        data: params,
        dataType: "json",
        success: function (data) {
            if (data.code == 1 && data.code != undefined) {
                list = data.list;
                page = data.page;
                var html = "";
                for (var l in list) {
                    html += '<tr><td>' + list[l].id + '</td>' +
                        '<td>' + list[l].nickName + '</td>' +
                        '<td>' + list[l].price + '</td>' +
                        '<td>' + list[l].order + '</td></tr>';
                }
                $("#partnerOrder").html(html);
                $("#total").html("共有数据：" + page.total + " 条");
                laypage({
                    cont: 'page'
                    , pages: page.pages
                    , first: 1
                    , curr: pageNum
                    , last: page.pages
                    , prev: '<em><</em>'
                    , next: '<em>></em>'
                    , jump: function (obj, first) {
                        pageNum = obj.curr;
                        if (!first) {
                            partnerOrder();
                        }
                    }
                });
            } else if (data == 9999 && data != undefined) {
                window.location.href = "/login_toLogin";
            } else if (data == 1111 && data != undefined) {
                alert("无权操作");
            }
        }
    });
}